package com.polytech.ihm;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;

import com.polytech.beans.Car;

public class PanelAd extends JPanel implements ListCellRenderer<Car>{

	private Car car;
	private boolean isSelected;
	private boolean focus;
	private JPanel panelInfo=new JPanel();
	private PanelPicture panelPic=new PanelPicture(80,80,PanelPicture.DEFINESIZE);
	private JLabel carInfo;


	public PanelAd() {


		panelInfo=new JPanel(new FlowLayout(FlowLayout.LEFT));
		this.setPreferredSize(new Dimension(100, 100));	
		carInfo=new JLabel("");
		carInfo.setPreferredSize(new Dimension(220, 80));
		panelInfo.add(carInfo);
		this.add(panelPic);
		panelPic.setBorder(BorderFactory.createBevelBorder(0));
		this.add(panelInfo);


	}
	public void showPic(){
		panelPic.show();
	}
	public void hidPic(){
		panelPic.hide();
	}

	@Override
	public Component getListCellRendererComponent(JList<? extends Car> list,
			Car car, int i, boolean isSelected, boolean focus) {

		carInfo.setText(""+car);
		panelPic.setPicture(car.getPicture());

		if(isSelected){
			this.setBorder(BorderFactory.createBevelBorder(1, Color.BLACK, Color.BLACK));
		}
		else{
			this.setBackground(list.getBackground());
			this.setBorder(BorderFactory.createBevelBorder(1, list.getBackground(),list.getBackground()));
	
		}
		return this;
	}


	@Override
	public Dimension getPreferredSize() {
		return new Dimension(350, 100);
	}



}
